package com.codermn.demo3;

import java.util.Objects;

/**
 * @author jxau_scf
 * @date 2021/5/31 - 16:09
 */
public class Student {
    private int id;
    private String name;
    private int age;
    private static String room;
    private static int idCounter = 0;

    public Student(){
        this.id = ++idCounter;
    }

    public Student(String name, int age) {
        this.id = ++idCounter;
        this.name = name;
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public static String getRoom() {
        return room;
    }

    public static void setRoom(String room) {
        Student.room = room;
    }

    public static int getIdCounter() {
        return idCounter;
    }

    public static void setIdCounter(int idCounter) {
        Student.idCounter = idCounter;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return id == student.id &&
                age == student.age &&
                name.equals(student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, age);
    }

    public static void main(String[] args) {
        Student stu1 = new Student("小哈",20);
        Student.room = "农大红楼";

        Student stu2 = new Student("小明", 22);
        System.out.println("姓名："+stu1.getName()+"学号："+stu1.getId()+"年龄："+stu1.getAge()+"教室："+getRoom());
        System.out.println("姓名："+stu2.getName()+"学号："+stu2.getId()+"年龄："+stu2.getAge()+"教室："+getRoom());

    }
}
